package com.wcy.controller.resource;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wcy.entity.ResourceTag;
import com.wcy.entity.ResourceTagMapping;
import com.wcy.entity.pageVo.ApiDescriptor;
import com.wcy.entity.pageVo.ColumnConstructor;
import com.wcy.entity.pageVo.PageData;
import com.wcy.feign.resource.FeignResourceTagMappingService;
import jakarta.annotation.Resource;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Objects;

@RestController
public class ResourceTagMappingController {
    @Resource
    private FeignResourceTagMappingService resourceTagMappingService;

    @GetMapping("resourceTagMapping/page")
    public ResponseEntity<PageData<ResourceTagMapping>> getPage(@RequestParam(defaultValue = "1") int pageNum,
                                                                @RequestParam(defaultValue = "10") int pageSize) {
        return ResponseEntity.ok(new PageData<>(ResourceTagMapping.class, Objects.requireNonNull(resourceTagMappingService.getPage(pageNum, pageSize).getBody()),  new ApiDescriptor("resourceTagMapping/add", "resourceTagMapping/update", "resourceTagMapping/delete"), ColumnConstructor.create()));
    }

    @GetMapping("resourceTagMapping/list")
    public ResponseEntity<List<ResourceTagMapping>> getList() {
        return resourceTagMappingService.getList();
    }
    @GetMapping("resourceTagMapping/add")
    public ResponseEntity<Void> add(@RequestBody ResourceTagMapping resourceTagMapping) {
        return resourceTagMappingService.add(resourceTagMapping);
    }
    @GetMapping("resourceTagMapping/update")
    public ResponseEntity<Void> update(@RequestBody ResourceTagMapping resourceTagMapping) {
        return resourceTagMappingService.update(resourceTagMapping);
    }
    @GetMapping("resourceTagMapping/delete/{id}")
    public ResponseEntity<Void> delete(@PathVariable Integer id) {
        return resourceTagMappingService.delete(id);
    }

}
